﻿using AIO.Entity;
using AIO.Entity.Base;
using AIO.IService;
using AIO.Service.Base;

namespace AIO.Service
{
    /// <summary>
    /// 账户仓库
    /// </summary>
    public class AccountRepository : BaseRepository<Account>, IAccountRepository
    {
        protected ApiDBContext _Context { get; set; }
        public AccountRepository(ApiDBContext dBContext) : base(dBContext)
        {
            _Context = dBContext ?? throw new ArgumentNullException(nameof(dBContext));
        }
        /// <summary>
        /// 登录验证
        /// </summary>
        /// <param name="AccountName">账户</param>
        /// <param name="AccountPassword">密码</param>
        /// <returns></returns>
        public Account? Login(string AccountName, string AccountPassword)
        {
            return _Context.Accounts.FirstOrDefault(
                s => s.AccountName == AccountName
                &&
                s.AccountPassword == AccountPassword
                );
        }
        /// <summary>
        /// 根据ID获取账户
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public Account? GetById(Guid Id)
        {
            return _Context.Accounts.FirstOrDefault(
                s => s.Id == Id
                );
        }
    }
}
